library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.4 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 2.0.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr)
library(ggridges)
library(ggplot2)
library(forcats)
library(p8105.datasets)
library(httr)
library(jsonlite)
##
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
##
## flatten
library(viridis)
## Loading required package: viridisLite
library(patchwork)
library(knitr)
library(png)
library(tidyverse)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:httr':
##
## config
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(p8105.datasets)
data("rest_inspec")
na.omit(rest_inspec)
## # A tibble: 192,069 × 18
## action boro building camis critical_flag cuisine_descrip… dba
## <chr> <chr> <chr> <int> <chr> <chr> <chr>
## 1 Violations w… MANHA… 1271 5.00e7 Critical American THE HARO…
## 2 Violations w… MANHA… 37 4.12e7 Not Critical Korean SHILLA K…
## 3 Violations w… MANHA… 53 4.04e7 Not Critical Korean HAN BAT …
## 4 Violations w… MANHA… 287 4.16e7 Not Critical American BRGR
## 5 Violations w… MANHA… 800 4.11e7 Not Critical Pizza WALDY'S …
## 6 Violations w… MANHA… 121 5.00e7 Not Critical Café/Coffee/Tea LUNA
## 7 Violations w… MANHA… 124 4.10e7 Critical American JOHNY'S …
## 8 Violations w… MANHA… 138 4.11e7 Critical American AROME CA…
## 9 Violations w… MANHA… 839 5.00e7 Not Critical American L'AMICO/…
## 10 Violations w… MANHA… 35 4.13e7 Critical Korean MADANGSUI
## # … with 192,059 more rows, and 11 more variables: inspection_date <dttm>,
## # inspection_type <chr>, phone <chr>, record_date <dttm>, score <int>,
## # street <chr>, violation_code <chr>, violation_description <chr>,
## # zipcode <int>, grade <chr>, grade_date <dttm>
rest_inspec=janitor::clean_names(rest_inspec)
rest_inspec<-filter(rest_inspec, boro %in% c("MANHATTAN", "BRONX", "QUEENS","BROOKLYN","STATEN ISLAND"))
critical<-filter(rest_inspec,critical_flag %in% c("Critical"), boro %in% c("MANHATTAN", "BRONX", "QUEENS","BROOKLYN","STATEN ISLAND"))
Manhattan<-filter(rest_inspec, boro %in% c("MANHATTAN"))
rest_inspec %>%
mutate(boro = fct_reorder(boro, score)) %>%
plot_ly(y = ~score, color = ~boro, type = "box", colors = "viridis")
## Warning: Ignoring 22636 observations
fig <- plot_ly(
type = 'scatter',
x = rest_inspec$cuisine_description,
y = rest_inspec$score,
mode = 'markers',
transforms = list(
list(
type = 'aggregate',
groups = rest_inspec$cuisine_description,
aggregations = list(
list(
target = 'y', func = 'sum', enabled = T
)
)
)
)
)
fig
## Warning: Ignoring 22636 observations